package com.logicwin.aibala.model.androidSWInfo;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import android.content.pm.PackageInfo;

/**
 * 描述手机上通过Aibala安装的软件信息
 * 
 * @author GuoDing
 *
 */
public class APKInstallInfo {
	private boolean isAibala = false;
	private int swID = -1;
	private String currVersion;
	private String apkFileName;
	private int currState;
	private String apkName = "";
	
	public APKInstallInfo(Node node) {
		this.isAibala = true;
		
		NodeList child = node.getChildNodes();
		for(int i = 0; i < child.getLength(); i++) {
			if(0 == child.item(i).getNodeName().compareTo("id")) {
				this.swID = Integer.valueOf(child.item(i).getNodeValue());
			}
			else if(0 == child.item(i).getNodeName().compareTo("currVersion")) {
				this.currVersion = new String(child.item(i).getNodeValue());
			}
			else if(0 == child.item(i).getNodeName().compareTo("apkFileName")) {
				this.apkFileName = new String(child.item(i).getNodeValue());
			}
			else if(0 == child.item(i).getNodeName().compareTo("currState")) {
				this.currState = Integer.valueOf(child.item(i).getNodeValue());
			}
		}
	}
	
	public APKInstallInfo(PackageInfo pi) {
		this.isAibala = false;
		
		this.apkName = new String(pi.applicationInfo.name);
		this.currVersion = new String(pi.versionName);
	}
	
	public boolean isAibala() {
		return this.isAibala;
	}
	
	public int getSWID() {
		return this.swID;
	}
	
	public String getCurrVersion() {
		return this.currVersion;
	}
	
	public String getAPKFileName() {
		return this.apkFileName;
	}
	
	public int getCurrState() {
		return this.currState;
	}
	
	/**
	 * 反悔APK名称，只针对非Aibala软件
	 * @return
	 */
	public String getAPKName() {
		return this.apkName;
	}
}
